package com.gali.juc;

import java.util.concurrent.TimeUnit;

/**
 * @Auther: gali
 * @Date: 2022-08-19 18:29
 * @Description:
 */
public class InterruptDemo2 {
    public static void main(String[] args) {
        Thread a = new Thread(() -> {
            while (true){
                if (Thread.currentThread().isInterrupted()){
                    System.out.println(Thread.currentThread().getName()+
                            "\t 中断标志位："+Thread.currentThread().isInterrupted()+"程序停止");
                    break;
                }


                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                    e.printStackTrace();
                }


                System.out.println("hello InterruptDemo2");
            }
        }, "a");
        a.start();

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        new Thread(()-> a.interrupt(),"b").start();
    }
}
